package com.CGFrame.struts.bean.unit;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.CGFrame.struts.POJOs.Projectconfig;
import com.CGFrame.struts.POJOs.Shotgroup;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.bean.material.MaterialBean;
import com.CGFrame.struts.bean.material.MaterialgroupBean;
import com.CGFrame.struts.bean.task.TaskBean;

public class FilePathGenerator {

	public static final int MediaFile = 0; // Media/Working
	public static final int ChangeFile = 4;// Media/Working;
	public static final int MakeFile = 1; // Make/Working
	public static final int FinishedMediaFile = 2; // Media//Approved
	public static final int FinishedMakeFile = 3; // Make//Approved

	public static ArrayList getFilePath(int objectId, String type) {
		// path="CCTV/Project/scenes/Assets/Production/Characters/ShiTong/";
		// path="CCTV/Project/scenes/Episodes/Episode001/Production/Shot/Shot002/";
		// D:\CCTV\Project\scenes\Episodes\Episode001\Production\Scene001\CCTV_Ep001_Sc001_Shot001
		StringBuffer path = new StringBuffer();
		ArrayList<StringBuffer> ret = new ArrayList<StringBuffer>();
		if (type.equals("Element")) {
			ElementBean eb = new ElementBean(objectId);
			LinkedList list = eb.getElementGroupName();
			String elementName = eb.getElementName();
			path.append(eb.getProjectName()).append("/Project/scenes/");
			path.append(list.poll()).append("/Production/");
			for (Iterator iter = list.iterator(); iter.hasNext();) {
				path.append(iter.next()).append("/");
			}
			path.append(elementName).append("/");
		}
		else if (type.equals("Shot")) {
			ShotBean sb = new ShotBean(objectId);
			ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
			Shotgroup sgp = (Shotgroup) pop.UniqueQuery("Shotgroup",
					"shotGroupId,"
							+ sb.getShot().getShotgroup().getShotGroupId());
			Projectconfig pconf = (Projectconfig) pop.UniqueQuery(
					"Projectconfig", "projectId,"
							+ sgp.getProject().getProjectId());
			path.append(pconf.getProjectName()).append("/Project/scenes/");
			List list = sb.getShotGroupName();

			if (list.size() > 0) {
				path.append(list.get(0));
				path.append("/");
			}

			if ((list.size() > 1) && (pconf.getHasEspCheck() == 1)) {
				path.append(list.get(1));
				path.append("/");
			}

			path.append("Production");
			path.append("/");

			if (pconf.getIsSingleShot() == 0 || pconf.getHasScenceCheck() == 0) {
				path.append("Shot");
			} else {
				path.append(list.get(list.size()-1));
			}
			path.append("/");
			path.append(sb.getShotName());
			path.append("/");
		}
		else if ("Materialgroup".equals(type))
		{
			MaterialgroupBean mgBean = new MaterialgroupBean(objectId);
			LinkedList<String> list = mgBean.getMaterialGroupNameList();
			while ( !(list.isEmpty()) )
			{
				path.append(list.poll()).append("/");
			}
			path.append(mgBean.getName()).append("/");
		}
		else if ("Material".equals(type))
		{
			MaterialBean mBean = new MaterialBean(objectId);
			LinkedList<String> list = mBean.getMaterialGroupNameList();
			while ( !(list.isEmpty()) )
			{
				path.append(list.poll()).append("/");
			}
			path.append(mBean.getName()).append("/");
		}
		ret.add(path);
		return ret;
	}
	public static StringBuffer getPreProductionPath(int objectId ,String type)
	{
		StringBuffer path = new StringBuffer();
		if (type.equals("Element")) {
			ElementBean eb = new ElementBean(objectId);
			LinkedList list = eb.getElementGroupName();
			String elementName = eb.getElementName();
			path.append(eb.getProjectName()).append("/Project/scenes/");
			path.append(list.poll()).append("/Pre_Production/");
			for (Iterator iter = list.iterator(); iter.hasNext();) {
				path.append(iter.next()).append("/");
			}
			path.append(elementName).append("/");
			
		}
		else if (type.equals("Shot")) {
			ShotBean sb = new ShotBean(objectId);
			ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
			Shotgroup sgp = (Shotgroup) pop.UniqueQuery("Shotgroup",
					"shotGroupId,"
							+ sb.getShot().getShotgroup().getShotGroupId());
			Projectconfig pconf = (Projectconfig) pop.UniqueQuery(
					"Projectconfig", "projectId,"
							+ sgp.getProject().getProjectId());
			path.append(pconf.getProjectName()).append("/Project/scenes/");
			List list = sb.getShotGroupName();

			if (list.size() > 0) {
				path.append(list.get(0));
				path.append("/");
			}

			if ((list.size() > 1) && (pconf.getHasEspCheck() == 1)) {
				path.append(list.get(1));
				path.append("/");
			}

			path.append("Pre_Production");
			path.append("/");
		}
		return path;
	}
	
	public  static StringBuffer getStoryBoard(int objectId,String type)
	{
		if ( type.equals("Shot") )
		{
			StringBuffer path = new StringBuffer();
			path = getPreProductionPath(objectId, type);
			path.append("Storyboard/Approved/");
			return path;
		}
		else
		{
			return null;
		}
	}
	public static StringBuffer getElementPrePath(int objectId,String type)
	{
		if (type.equals("Element"))
		{
			StringBuffer path = new StringBuffer();
			path = getPreProductionPath(objectId,type);
			path.append("Media/Approved/");
			return path;
		}
		else
		{
			return null;
		}
	}
	
	

}
